1 00:00:00,350 --> 00:00:06,830 I am in my battle royale arena and now we have to make it so that the last person standing is declared 2 00:00:06,830 --> 00:00:07,520 the winner. 3 00:00:07,550 --> 00:00:11,600 They are given some sort of prize and then they're teleported back. 4 00:00:11,600 --> 00:00:17,510 Let's go to our battle manager under server script service and take a look at that. 5 00:00:17,660 --> 00:00:23,750 Let's go to our variable section up at the top, make a flag to determine whether the battle is ended 6 00:00:23,750 --> 00:00:24,440 or not. 7 00:00:24,440 --> 00:00:28,670 I'm going to say is ended and I'm going to initialize it to false. 8 00:00:28,700 --> 00:00:37,520 Now, in the battle itself, after we tell people, hey, it's begun, so run, hide, start shooting, 9 00:00:37,520 --> 00:00:40,520 whatever you get your weapons, let's make a while loop. 10 00:00:40,520 --> 00:00:50,690 Let's say while not is ended, do let's put a wait statement in there so we don't we don't exhaust our 11 00:00:50,690 --> 00:00:51,740 resources. 12 00:00:52,400 --> 00:00:55,160 Let me just scroll this code up a little bit. 13 00:00:55,550 --> 00:00:56,390 There we go. 14 00:00:56,390 --> 00:00:57,850 And we'll continue. 15 00:00:57,860 --> 00:01:04,460 Let's get the number of players, local num equals number of players. 16 00:01:04,460 --> 00:01:05,600 But that's a service. 17 00:01:05,600 --> 00:01:10,460 We have to get the children in the service to get the number and then I'll check to see if the number 18 00:01:10,460 --> 00:01:12,620 of players equals equals one. 19 00:01:13,220 --> 00:01:16,400 If it does, we have a last person standing. 20 00:01:16,400 --> 00:01:18,440 Let's go ahead and get that player. 21 00:01:18,470 --> 00:01:19,790 Local player. 22 00:01:20,060 --> 00:01:23,560 I'll say players get children. 23 00:01:23,570 --> 00:01:27,380 I probably should have made an array out of this so that I wouldn't have to do something weird like 24 00:01:27,380 --> 00:01:27,950 this. 25 00:01:27,950 --> 00:01:34,490 So it's going to get the first element in this array, right? 26 00:01:34,490 --> 00:01:38,510 I don't usually like to combine stuff like that, but I'll do it here. 27 00:01:38,930 --> 00:01:43,340 Let's do an if statement just to make sure the player exists. 28 00:01:43,370 --> 00:01:49,820 Although this would probably you would probably error if this didn't work and then this if statement 29 00:01:49,820 --> 00:01:50,570 would be irrelevant. 30 00:01:50,570 --> 00:01:57,240 But let's put it in there just in case we'll get an is ended equals true, right? 31 00:01:57,240 --> 00:01:58,950 Because there's one player left. 32 00:01:59,190 --> 00:02:00,270 The battle ended. 33 00:02:00,270 --> 00:02:02,130 We don't want to check anymore. 34 00:02:02,130 --> 00:02:04,830 And then let's do a print statement. 35 00:02:05,580 --> 00:02:06,050 Right. 36 00:02:06,090 --> 00:02:08,760 See if things are things are printing out properly. 37 00:02:08,760 --> 00:02:14,070 We'll do winner and the player.name. 38 00:02:15,570 --> 00:02:18,090 And then what should we give the player if they win? 39 00:02:18,090 --> 00:02:27,360 Let's do player leader stats points dot value plus equals 200. 40 00:02:27,360 --> 00:02:33,240 We'll give them 200 points on the leaderboard on the leader stats and then our game manager is saving 41 00:02:33,240 --> 00:02:36,480 stuff off on this side too, so we shouldn't have a problem with it. 42 00:02:36,780 --> 00:02:41,280 And we have it for the player removing event two or saving things off. 43 00:02:41,400 --> 00:02:50,460 Let's do our status RE to the client side so we get a little a little message, a little banner popping 44 00:02:50,460 --> 00:02:52,110 up player. 45 00:02:54,130 --> 00:02:56,890 So then we're going to send in two parameters. 46 00:02:56,920 --> 00:03:04,120 Our battle info, which was the client side script for our little UI, is expecting two parameters. 47 00:03:04,120 --> 00:03:05,950 You don't have to worry about this one. 48 00:03:05,950 --> 00:03:10,390 This player right here just says, Hey, fire client to this player. 49 00:03:10,420 --> 00:03:17,860 That's not going to show up in your battle info log script, but you are going to get a status. 50 00:03:17,860 --> 00:03:19,450 Remember, we'll take a look at it a minute. 51 00:03:19,480 --> 00:03:20,530 We have a win. 52 00:03:20,530 --> 00:03:22,450 It's begin, prepare and win. 53 00:03:22,450 --> 00:03:27,610 Those were the statuses are if conditions we're looking for and then we're going to have our message 54 00:03:28,780 --> 00:03:29,860 you are the winner. 55 00:03:29,860 --> 00:03:30,520 How about that? 56 00:03:30,520 --> 00:03:33,370 You are the winner. 57 00:03:33,370 --> 00:03:34,720 Yay. 58 00:03:35,110 --> 00:03:35,740 Cool. 59 00:03:35,740 --> 00:03:37,390 And then what else do we need to do? 60 00:03:37,390 --> 00:03:39,250 So we sent our message. 61 00:03:39,250 --> 00:03:41,020 We're going to get the UI pop up. 62 00:03:41,020 --> 00:03:45,340 Let's wait three seconds so that you can look at it, Make it five if you want. 63 00:03:45,370 --> 00:03:48,730 Maybe give them a little time to bask in their glory. 64 00:03:48,730 --> 00:03:51,970 But after we wait, we want to teleport back. 65 00:03:51,970 --> 00:03:56,900 So we're going to use the teleport service and then we'll do our teleport. 66 00:03:57,050 --> 00:04:01,970 We're going to get our home ID, and then we'll get our player to send back. 67 00:04:02,000 --> 00:04:03,380 There's only one player left. 68 00:04:03,380 --> 00:04:04,550 Let's send them back. 69 00:04:04,550 --> 00:04:09,410 But I want to test this out in Roblox studio. 70 00:04:09,410 --> 00:04:14,870 Teleport is no bueno for studio, so I'm going to do a little trick. 71 00:04:14,870 --> 00:04:16,700 I'm going to scroll up to the top. 72 00:04:17,170 --> 00:04:25,240 In the variable section here, and I'm going to get a variable for the run service run SVR. 73 00:04:25,270 --> 00:04:27,610 Let's call it that game. 74 00:04:27,610 --> 00:04:30,670 Get service, run service. 75 00:04:30,670 --> 00:04:33,130 And then I could check to see if I'm in studio. 76 00:04:33,790 --> 00:04:36,880 So we come down here, do a little if statement. 77 00:04:36,910 --> 00:04:43,840 If not, run service is studio. 78 00:04:43,870 --> 00:04:45,880 Then we'll teleport. 79 00:04:45,910 --> 00:04:50,380 Otherwise we'll just skip over it because we have to test it out. 80 00:04:50,380 --> 00:04:55,000 And then here's our here is our number of players equals one. 81 00:04:55,030 --> 00:04:56,410 Let's get down here. 82 00:04:58,090 --> 00:04:59,530 Maybe do a little print out. 83 00:04:59,560 --> 00:05:00,580 Should we do print out? 84 00:05:00,610 --> 00:05:01,720 We could do a print out. 85 00:05:01,750 --> 00:05:02,980 It won't hurt anything. 86 00:05:03,070 --> 00:05:04,570 We'll do there. 87 00:05:04,610 --> 00:05:04,950 Whoops. 88 00:05:04,960 --> 00:05:07,150 There is. 89 00:05:07,540 --> 00:05:09,100 There are. 90 00:05:09,220 --> 00:05:11,710 And then we'll do the number of players. 91 00:05:11,710 --> 00:05:16,790 Right that way, if there's if there's a problem, we can kind of see what's going on. 92 00:05:17,200 --> 00:05:19,740 It's good to have print outs, especially in your debugging. 93 00:05:19,760 --> 00:05:20,180 All right. 94 00:05:20,180 --> 00:05:21,380 This is pretty cool. 95 00:05:21,380 --> 00:05:24,830 I think it's ready to give a dry run in studio. 96 00:05:26,250 --> 00:05:27,570 Let's go to play. 97 00:05:28,830 --> 00:05:29,940 See what we got. 98 00:05:34,340 --> 00:05:36,500 Eight, seven, six, five. 99 00:05:36,530 --> 00:05:37,340 That's pretty cool. 100 00:05:41,330 --> 00:05:43,010 Let the games begin. 101 00:05:43,490 --> 00:05:45,680 And I'm the winner because I'm the last player. 102 00:05:45,960 --> 00:05:48,290 And I didn't even even check to see if I got more points. 103 00:05:48,290 --> 00:05:49,200 I'm assuming I did. 104 00:05:49,220 --> 00:05:49,790 I'll check. 105 00:05:49,790 --> 00:05:52,790 I'll check before I publish the video, but that's pretty cool. 106 00:05:52,790 --> 00:05:56,180 And then we didn't get an error for our. 107 00:05:57,570 --> 00:05:58,680 There are one players. 108 00:05:58,680 --> 00:06:02,560 We didn't get an error because we skipped right over our teleport because we are in studio. 109 00:06:02,580 --> 00:06:06,210 Let's go ahead and try this on Roblox. 110 00:06:07,860 --> 00:06:09,450 So I got my alt right here. 111 00:06:09,450 --> 00:06:12,830 He's on the phone, so it might take a while to bumble around with that. 112 00:06:12,840 --> 00:06:17,820 If you'll notice, the points are correct and they saved off. 113 00:06:17,820 --> 00:06:22,530 So that's cool because we do have saving on the arena side of things. 114 00:06:22,530 --> 00:06:24,300 Start our battle. 115 00:06:24,300 --> 00:06:28,620 I'm going to accept I'm going to pick up my phone here and I'm going to hit the accept for my alt. 116 00:06:29,280 --> 00:06:33,840 We're both going to end up in the other world and my ALT has 90 points. 117 00:06:33,840 --> 00:06:35,850 Let's have oh, he doesn't have a gun. 118 00:06:35,880 --> 00:06:37,320 It's going to say, let's have him win. 119 00:06:37,320 --> 00:06:39,090 But he can't. 120 00:06:40,730 --> 00:06:41,900 Here we go. 121 00:06:45,190 --> 00:06:46,210 Cool. 122 00:06:47,110 --> 00:06:48,250 Hey, there he is. 123 00:06:48,280 --> 00:06:49,810 Hey, man, What are you doing here? 124 00:06:50,560 --> 00:06:51,340 We're going to shoot you. 125 00:06:52,210 --> 00:06:54,070 Let the games begin. 126 00:06:54,250 --> 00:06:55,210 Get my gun. 127 00:06:57,680 --> 00:06:59,540 Oh, man, I should have cranked that up. 128 00:06:59,960 --> 00:07:05,300 I paused the video because it was healing almost as fast as the gun was was hurting him. 129 00:07:05,690 --> 00:07:07,160 There we go. 130 00:07:10,460 --> 00:07:10,740 Ha. 131 00:07:11,080 --> 00:07:11,950 Yeah. 132 00:07:13,540 --> 00:07:14,980 And we're going back. 133 00:07:15,400 --> 00:07:16,210 That's pretty cool. 134 00:07:16,210 --> 00:07:20,470 Let's make sure our alts there he is nice. 135 00:07:20,470 --> 00:07:21,190 And he didn't. 136 00:07:21,220 --> 00:07:23,050 He didn't win anything. 137 00:07:23,050 --> 00:07:28,450 We got an extra kill and he got an extra death.